package com.example.myapplication.base;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class UITabFragment extends UIFragment {

    @Nullable
    public UITransitionAnimation getDefaultSelectTabAnimation(@IdRes int containerViewId) {
        return getUIFragmentManager(containerViewId).getDefaultSelectTabAnimation();
    }

    public void setDefaultSelectTabAnimation(@IdRes int containerViewId,
                                             @Nullable UITransitionAnimation animation) {
        getUIFragmentManager(containerViewId).setDefaultSelectTabAnimation(animation);
    }

    @Nullable
    @Override
    public UIFragment setContentFragment(@IdRes int containerViewId,
                                         @NonNull Class<? extends UIFragment> cls) {
        return null;
    }

    @NonNull
    public List<UIFragment> popToRootFragment(@IdRes int containerViewId) {
        return popToRootFragment(containerViewId, null);
    }

    public boolean existTab(@IdRes int containerViewId) {
        UIFragment fragment = getUIFragmentManager(containerViewId).peekTop();
        return fragment != null;
    }

    @NonNull
    public List<UIFragment> popToRootFragment(@IdRes int containerViewId,
                                              @Nullable UIFragmentTransaction transaction) {
        return getUIFragmentManager(containerViewId).popToRoot(transaction);
    }

    public void addTab(@IdRes int containerViewId, @NonNull String name,
                       @NonNull Class<? extends UIFragment> cls) {
        addTab(containerViewId, new UITabInfo(name, cls));
    }

    public void addTab(@IdRes int containerViewId, @NonNull String name,
                       @NonNull Class<? extends UIFragment> cls, @Nullable String tag) {
        addTab(containerViewId, new UITabInfo(name, cls, tag));
    }

    public boolean addTab(@IdRes int containerViewId, @NonNull UITabInfo tabInfo) {
        return getUIFragmentManager(containerViewId).addTab(tabInfo);
    }

    public boolean removeTab(@IdRes int containerViewId, @NonNull String name) {
        return getUIFragmentManager(containerViewId).removeTab(name);
    }

    @Nullable
    public String getSelectedTabName(@IdRes int containerViewId) {
        return getUIFragmentManager(containerViewId).getSelectedTabName();
    }

    @Nullable
    public UIFragment setSelectedTabName(@IdRes int containerViewId, @NonNull String name) {
        return setSelectedTabName(containerViewId, name, null);
    }

    @Nullable
    public UIFragment setSelectedTabName(@IdRes int containerViewId, @NonNull String name,
                                         @Nullable UIFragmentTransaction transaction) {
        return getUIFragmentManager(containerViewId).setSelectedTabName(name, transaction);
    }

}
